package Java复习;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class Frame extends JFrame{
    public Frame() throws HeadlessException {
        scree();
        this.setVisible(true);
    }
    public void scree(){
        JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
        JLabel jLabel = new JLabel("你好");
        jPanel.add(jLabel);
        this.add(jPanel, BorderLayout.NORTH);
        JButton button = new JButton("点击");
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String text = jLabel.getText();
                if ("你好".equals(text)){
                    jLabel.setText("welcome");
                }else {
                    jLabel.setText("byebye");
                }

            }
        });
        this.add(button, BorderLayout.CENTER);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
        this.setAlwaysOnTop(true);
        this.pack();
    }
}
public class 图形Num1 {
    public static void main(String[] args) {
        Frame f = new Frame();
    }
}
